fix(stm32cubeprog): harden getopt support on MacOS#120
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates stm32CubeProg.sh to improve macOS robustness around GNU getopt availability, aiming to support both Homebrew (including non-default prefixes) and MacPorts installs so the script can reliably accept long options when GNU getopt is present.
Changes:
- Adds macOS (
Darwin) logic to detect GNU vs BSDgetoptand to extendPATHfor Homebrew/MacPorts installs. - Switches argument parsing to use long options only when GNU
getoptis available, otherwise falls back to short-option parsing with warnings.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
stm32CubeProg.sh:101
- GNU getopt detection is inverted:
getopt --testreturns exit code 4 on GNU getopt (and errors on BSD getopt), soif ! getopt --test; then GNU_GETOPT="y"will incorrectly mark BSD getopt as GNU, causing the script to run GNU-style long-option parsing on macOS and fail. Check explicitly for exit status 4 instead.
if command -v getopt >/dev/null 2>&1; then
if ! getopt --test 2>/dev/null; then
GNU_GETOPT="y"
fi
fi
stm32CubeProg.sh:109
- Homebrew GNU getopt lookup is checking
${BREW_PREFIX}/bin/getopt, butgnu-getoptis keg-only by default and typically lives under${BREW_PREFIX}/opt/gnu-getopt/bin/getopt. With a non-default Homebrew prefix, this check will usually miss GNU getopt and the later hardcoded/usr/local//opt/homebrewfallbacks won't apply, so long options remain broken.
BREW_PREFIX=$(brew --prefix)
# Only check in bin as brew symlinks its files into the prefix,
if command -v "${BREW_PREFIX}/bin/getopt" >/dev/null 2>&1; then
export PATH="${BREW_PREFIX}/bin":"$PATH"
GNU_GETOPT="y"
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
stm32CubeProg.sh:90
- Homebrew getopt detection stops after checking "${BREW_PREFIX}/bin/getopt" even when that binary exists but is not GNU (e.g., a non-GNU getopt wrapper). In that case the script never falls back to checking the typical keg-only path "${BREW_PREFIX}/opt/gnu-getopt/bin/getopt". Consider (1) quoting the brew prefix assignment and (2) only short-circuiting to the next candidate if the first candidate fails the GNU "--test" check.
BREW_PREFIX=$(brew --prefix)
if command -v "${BREW_PREFIX}/bin/getopt" >/dev/null 2>&1; then
"${BREW_PREFIX}"/bin/getopt --test >/dev/null 2>&1
- brew prefix usage - MacPorts support Fixes stm32duino#115 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #115.
Supersede #113.
@ndoo if you can test it will be fine.